//
//  StatusCellBottomView.swift
//  01- 搭建框架
//
//  Created by apple on 15/10/19.
//  Copyright © 2015年 任伟. All rights reserved.
//

import UIKit

/// 底部视图
class StatusCellBottomView: UIView {

    ///  构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// MARK: -懒加载控件
    // 转发按钮
    private lazy var forwardButton: UIButton = UIButton(title: " 转发",
        fontSize: 12,
        color: UIColor.lightGrayColor(),
        imageName: "timeline_icon_retweet")
    // 评论按钮
    private lazy var commentButton: UIButton = UIButton(title: " 评论",
        fontSize: 12,
        color: UIColor.lightGrayColor(),
        imageName: "timeline_icon_comment")
    // 点赞按钮
    private lazy var likeButton: UIButton = UIButton(title: " 赞",
        fontSize: 12,
        color: UIColor.lightGrayColor(),
        imageName: "timeline_icon_like")

}

/// MARK: - 设置界面
extension StatusCellBottomView {
    
    private func setupUI() {
    
        backgroundColor = UIColor(white: 0.95, alpha: 1.0)

        // 1. 添加控件
        addSubview(forwardButton)
        addSubview(commentButton)
        addSubview(likeButton)
        
        // 2. 自动布局
        forwardButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.bottom.equalTo(self.snp_bottom)
        }
        commentButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(forwardButton.snp_right)
            make.top.equalTo(forwardButton.snp_top)
            make.width.equalTo(forwardButton.snp_width)
            make.height.equalTo(forwardButton.snp_height)
        }
        likeButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentButton.snp_right)
            make.top.equalTo(forwardButton.snp_top)
            make.width.equalTo(forwardButton.snp_width)
            make.height.equalTo(forwardButton.snp_height)
            
            make.right.equalTo(self.snp_right)
        }
        
        let sep1 = sepView()
        let sep2 = sepView()
        addSubview(sep1)
        addSubview(sep2)
        
        // 分割线的自动布局
        let sepWidth = 0.6
        let sepScale = 0.4
        
        sep1.snp_makeConstraints { (make) -> Void in
                make.left.equalTo(forwardButton.snp_right)
                make.centerY.equalTo(forwardButton.snp_centerY)
                make.width.equalTo(sepWidth)
                make.height.equalTo(forwardButton.snp_height).multipliedBy(sepScale)
        }
        sep2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentButton.snp_right)
            make.centerY.equalTo(forwardButton.snp_centerY)
            make.width.equalTo(sepWidth)
            make.height.equalTo(forwardButton.snp_height).multipliedBy(sepScale)
        }
        
    }
    
    // 分割线视图
    private func sepView() -> UIView {
        
        let v = UIView()
        v.backgroundColor = UIColor.darkGrayColor()
        return v
    }
    
}